package com.hjx.controller;

import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.hjx.response.AjaxResponse;
import com.hjx.response.ResponseType;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 *
 * @author hjx
 * @date 2020/6/11 - 15:29
 */
@RestControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler({JWTVerificationException.class, JWTDecodeException.class})
    public AjaxResponse error(Exception e){
        return new AjaxResponse(1,e.getMessage(),null);
    }

    @ExceptionHandler(Exception.class)
    public AjaxResponse UnknownException(Exception e){
        e.printStackTrace();
        return new AjaxResponse(ResponseType.UNKNOWN_ERROR,e.getMessage());
    }
}
